/**
 * 模板素材模块
 */
define( [
	'jquery',
	'require',
	'../modules/createEditor',
	'transit',
	'constants'
], function( $, require ) {

	var returnParam = {};

	var ue = require( '../modules/createEditor' );
	var c = require( 'constants' );

	var $templatePreviw = returnParam.$selector = $( '.formwork_preview' ).on( 'click', '.preview_header .close', function() {
			$templatePreviw.transit( {
				y: 700,
				opacity: 0
			}, function() {
				$( this ).hide();
			} );
		} )
		/*.on( 'click', '.formwork_preview_content .brushStyle', function() {
				var thisOuterHTML = $( $( this ).parent().prop( 'outerHTML' ) );
				$( '.brushStyle', thisOuterHTML ).remove();
				ue.execCommand( 'inserthtml', thisOuterHTML.prop( 'outerHTML' ) || '' )
			} );*/

	function insertBrush( content ) {
		content = content.replace( /\/Public\/static/g, c.imgDomain[ 0 ] ).replace( /\r|\n/g, '' );
		content = $( '<div>' + content + '</div>' );
		$( '.135editor, ._135editor', content ).each( function() {
			$( this ).prepend( '<button type="button" class="btn btn-warning js_brush_style brushStyle">应用此样式</button>' )
		} );
		return content.html();
	}

	returnParam.contentRander = function( content ) {
		$templatePreviw.data( {
			'tid': content.tid,
			'tempType': content.tempType
		} );

		$( '.formwork_preview_body .formwork_preview_content', $templatePreviw ).html( insertBrush( content.content ) ).mediaSrcAttr().mediaFormat();
	}

	returnParam.show = function( title ) {
		$( '.template_title_text', $templatePreviw ).text( ( title || '未命名模板' ) + '-预览' )
		$( '.formwork_preview_body .formwork_preview_content', $templatePreviw ).html( '<div class="spinner"><div class="bounce1"></div><div class="bounce2"></div><div class="bounce3"></div></div>' );
		this.slideIn();
	}

	returnParam.slideIn = function() {
		$templatePreviw.show()[ 0 ]//.offsetWidth

		$templatePreviw.transit( {
			y: 0,
			opacity: 1
		}, 'ease-in' );

	}

	return returnParam;
} );